using System.Collections.Generic;

using OpenTK;

namespace ColladaDotNet.OpenTKMapping
{
	public abstract class Source : DocumentLibraryElement<source>,IDoubleArray
	{
		public abstract Vector4 GetVector4(ulong i);

		public abstract Vector3 GetVector3(ulong i);

		internal override void Load(source colladaData)
		{
			base.Load(colladaData);

			Elements = Collada.technique_common.accessor.count;
			foreach (var param in Collada.technique_common.accessor.param)
			{
				SourceParam element = Document.CreateElement<SourceParam>(param);
				element.Source = this;
				paramsList.Add(element);
				if (!string.IsNullOrEmpty(param.name))
					args[param.name] = element;
			}
		}
		Dictionary<string,SourceParam> args = new Dictionary<string, SourceParam>();
		List<SourceParam> paramsList = new List<SourceParam>();

		private ulong elements;

		public SourceParam this[int key]
		{
			get
			{
				return paramsList[key];
			}
		}
		public SourceParam this[string key]
		{
			get
			{
				SourceParam res;
				if (args.TryGetValue(key, out res))
					return res;
				return null;
			}
		}

		public virtual ulong Count
		{
			get
			{
				return 0;
			}
		}

		public ulong Elements
		{
			get
			{
				return elements;
			}
			set
			{
				elements = value;
			}
		}

		public abstract Matrix4d GetMatrix4d(ulong i);

		public abstract double GetDouble(ulong i);

		public abstract string GetString(ulong i);

		public Vector3d GetVector3d(ulong index)
		{
			var v= GetVector3(index);
			return new Vector3d(v.X, v.Y, v.Z);
		}
	}
}